#include "message.hpp"
#include "net.hpp"


// int main()
// {
// RPC::RpcRequest::ptr rrp = RPC::MessageFactory::create<RPC::RpcRequest>();
// Json::Value param;
// param["num1"] = 11;
// param["num2"] = 22;

// rrp->setMethod("Add");
// rrp->setparams(param);
// std::string str = rrp->serialize();
// std::cout << str << std::endl;

// RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::REQ_RPC);
// bool ret = bmp->unserialize(str);
// if(ret == false) return -1;
// ret = bmp->check();
// if(ret == false) return -1;

// RPC::RpcRequest::ptr rrp2 = std::dynamic_pointer_cast<RPC::RpcRequest>(bmp);
// std::cout << rrp2->method() << std::endl;
// std::cout << rrp2->params()["num1"].asInt()<< std::endl;
// std::cout << rrp2->params()["num2"].asInt()<< std::endl;

// RPC::TopicRequest::ptr trp = RPC::MessageFactory::create<RPC::TopicRequest>();
// trp->setTopicKey("news");
// trp->setOptype(RPC::TopicOpType::TOPIC_PUBLISH);
// trp->setTopicMsg("hello world!");
// std::string str = trp->serialize();
// std::cout << str << std::endl;

// RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::REQ_TOPIC);
// bool ret = bmp->unserialize(str);
// if(ret == false) return -1;
// ret = bmp->check();
// if(ret == false) return -1;

// RPC::TopicRequest::ptr trp2 = std::dynamic_pointer_cast<RPC::TopicRequest>(bmp);
// std::cout << trp2->topicKey() << std::endl;
// std::cout << (int)trp2->Optype() << std::endl;
// std::cout << trp2->topicMsg() << std::endl;

// RPC::ServiceRequest::ptr srp = RPC::MessageFactory::create<RPC::ServiceRequest>();
// srp->setMethod("Add");
// srp->setOptype(RPC::ServiceOpType::SERVICE_DISCOVERY);
// srp->setHost(RPC::Address("127.0.0.1", 9090));
// std::string str = srp->serialize();
// std::cout << str << std::endl;

// RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::REQ_SERVICE);
// bool ret = bmp->unserialize(str);
// if(ret == false) return -1;
// ret = bmp->check();
// if(ret == false) return -1;

// RPC::ServiceRequest::ptr trp2 = std::dynamic_pointer_cast<RPC::ServiceRequest>(bmp);
// std::cout << trp2->method() << std::endl;
// std::cout << (int)trp2->Optype() << std::endl;
// std::cout << trp2->host().first << std::endl;
// std::cout << trp2->host().second << std::endl;

// RPC::RpcResponse::ptr srp = RPC::MessageFactory::create<RPC::RpcResponse>();
// srp->setRCode(RPC::RCode::RCODE_OK);
// srp->setResult(33);
// std::string str = srp->serialize();
// std::cout << str << std::endl;

// RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::RSP_RPC);
// bool ret = bmp->unserialize(str);
// if(ret == false) return -1;
// ret = bmp->check();
// if(ret == false) return -1;

// RPC::RpcResponse::ptr trp2 = std::dynamic_pointer_cast<RPC::RpcResponse>(bmp);
// std::cout << (int)trp2->rcode() << std::endl;
// std::cout << trp2->result().asInt() << std::endl;

// RPC::TopicResponse::ptr srp = RPC::MessageFactory::create<RPC::TopicResponse>();
// srp->setRCode(RPC::RCode::RCODE_OK);
// std::string str = srp->serialize();
// std::cout << str << std::endl;

// RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::RSP_TOPIC);
// bool ret = bmp->unserialize(str);
// if(ret == false) return -1;
// ret = bmp->check();
// if(ret == false) return -1;

// RPC::TopicResponse::ptr trp2 = std::dynamic_pointer_cast<RPC::TopicResponse>(bmp);
// std::cout << (int)trp2->rcode() << std::endl;

//     RPC::ServiceResponse::ptr srp = RPC::MessageFactory::create<RPC::ServiceResponse>();
//     srp->setRCode(RPC::RCode::RCODE_OK);
//     srp->setMethod("Add");
//     srp->setOptype(RPC::ServiceOpType::SERVICE_DISCOVERY);
//     std::vector<RPC::Address> addrs;
//     addrs.push_back(RPC::Address("127.0.0.1", 9090));
//     addrs.push_back(RPC::Address("127.0.0.1", 9091));
//     srp->setHost(addrs);
//     std::string str = srp->serialize();
//     std::cout << str << std::endl;

//     RPC::BaseMessage::ptr bmp = RPC::MessageFactory::create(RPC::MType::RSP_SERVICE);
//     bool ret = bmp->unserialize(str);
//     if(ret == false) return -1;
//     ret = bmp->check();
//     if(ret == false) return -1;

//     RPC::ServiceResponse::ptr trp2 = std::dynamic_pointer_cast<RPC::ServiceResponse>(bmp);
//     std::cout << (int)trp2->rcode() << std::endl;
//     std::cout << (int)trp2->Optype() << std::endl;
//     std::cout << trp2->method() << std::endl;
//     std::vector<RPC::Address> addrs2 = trp2->Hosts();
//     for(auto& addr : addrs2)
//     {
//         std::cout << addr.first << ":" << addr.second << std::endl;
//     }
//     return 0;
// }

// #include "detail.hpp"

// int main()
// {
//     for(int i = 0; i < 10; i++)
//     {
//         RPC::UUID id;
//         std::cout << id.uuid() << std::endl;
//     }
//     return 0;
// }